﻿using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using System.Diagnostics;


namespace Auction_Boxing_2
{
    public enum DirectionType
    {
        Right,
        Left,
        Up,
        Down,
        None

    }

    public class StateJumping : State
    {
        // variable used for the shadow
        int startOfJump;

        const int JumpInterval = 3;
        const int CounterConst = 20;

        DirectionType Direction;
        GameTimer Timer;

        float UpInterval = 500;
        float DownInterval = 500;

        public StateJumping(DirectionType direction, State state)
        {

            StateName = "jumping";
            this.ATextures = state.StatePlayer.ATextures;

            Timer = new GameTimer(UpInterval, DownInterval);

            LoadState(state.StatePlayer, ATextures);

            Direction = direction;
            if (direction == DirectionType.None)
                Direction = DirectionType.Up;

            startOfJump = (int)state.StatePlayer.Position.Y;
        }

        public override void LoadState(BoxingPlayer player, Dictionary<string, Animation> ATextures)
        {
            this.StatePlayer = player;
            this.PlayerAnimation = ATextures[StateName];
            StatePlayer.isAttacking = false;
            StatePlayer.isHit = false;

            Timer.Start();

            /*if (StatePlayer.KeysDown.Contains(KeyPressed.Left) && !StatePlayer.KeysDown.Contains(KeyPressed.Right))
            {
                Direction = DirectionType.Left;
            }
            else if (StatePlayer.KeysDown.Contains(KeyPressed.Right) && !StatePlayer.KeysDown.Contains(KeyPressed.Left))
            {
                Direction = DirectionType.Right;
            }
            else
            {
                Direction = DirectionType.Up;
            }*/

            


        }

        public override void Initialize()
        {

        }

        public override void HandleMovement()
        {
            switch (Direction)
            {
                case DirectionType.Right:
                    if (Timer.Enabled && !Timer.Active)
                        Translate(JumpInterval, -JumpInterval);
                    else if (Timer.Active)
                        Translate(JumpInterval, JumpInterval);
                    break;

                case DirectionType.Left:
                    if (Timer.Enabled && !Timer.Active)
                        Translate(-JumpInterval, -JumpInterval);
                    else if (Timer.Active)
                        Translate(-JumpInterval, JumpInterval);
                    break;

                case DirectionType.Up:
                    if (Timer.Enabled && !Timer.Active)
                        Translate(0, -JumpInterval);
                    else if (Timer.Active)
                        Translate(0, JumpInterval);
                    break;
            }
        }

        public override void HandleDirection()
        {

        }

        public override void Update(GameTime gameTime)
        {


        }

        public override void HandleState()
        {
            if (!Timer.Enabled)
                StatePlayer.InternalState = new StateMoving(this);
            StatePlayer.rShadow.Y = startOfJump - 5 - StatePlayer.rShadow.Height;
        }

        public override void Translate(float x, float y)
        {
            Vector3 Temp = StatePlayer.Position;
            Temp.X += x;
            Temp.Y += y;
            StatePlayer.Position = Temp;

        }


        public override void HandleCollision(List<BoxingPlayer> Players)
        {

        }
    }
}
